package com.stxx.stiot2.controller;

import com.stxx.framwork.domain.R;
import com.stxx.framwork.domain.model.PageQuery;
import com.stxx.framwork.domain.model.PageResult;
import com.stxx.stiot2.domain.Device;
import com.stxx.stiot2.domain.Scene;
import com.stxx.stiot2.service.DeviceService;
import com.stxx.stiot2.service.SceneService;
import org.noear.solon.annotation.*;

import java.sql.SQLException;
import java.util.List;

@Controller
@Mapping("/scene")
public class SceneController {

    @Inject
    SceneService baseService;

    @Get
    @Mapping("/list")
    public PageResult<Scene> list(Scene bo, PageQuery pageQuery) throws SQLException {
        PageResult<Scene> r = baseService.pageList(bo,pageQuery);
        return r;
    }


    @Get
    @Mapping("/profile/{code}/list")
    public List<Scene> listByProfileCode(@Path String code) throws SQLException {
        List<Scene> r = baseService.queryByProfileCode(code);
        return r;
    }

    @Get
    @Mapping("/terminal/{code}/list")
    public List<Scene> listByTerminalCode(@Path String code) throws SQLException {
        List<Scene> r = baseService.queryByTerminalCode(code);
        return r;
    }


    @Get
    @Mapping("/{profileCode}/{terminalCode}/list")
    public List<Scene> listByTerminalCode(@Path String profileCode,@Path String terminalCode) throws SQLException {
        List<Scene> r = baseService.queryForExec(profileCode,terminalCode);
        return r;
    }


    @Post
    @Mapping("")
    public R<Object> add(@Body Scene bo) throws SQLException {
        baseService.insert(bo);
        return R.ok("数据保存成功");
    }

    @Put
    @Mapping("")
    public R<Object> edit(@Body Scene bo) throws SQLException {
        baseService.update(bo);
        return R.ok("数据保存成功");
    }


    @Put
    @Mapping("/changeStatus/{id}/{status}")
    public R<Object> changeStatus(@Path Integer id,@Path Boolean status) throws SQLException {
        baseService.changeStatus(id,status);
        return R.ok("数据保存成功");
    }

    @Delete
    @Mapping("/{ids}")
    public R<Object> remove(@Path Integer[] ids) throws SQLException {
        baseService.deleteByIds(ids);
        return R.ok("数据删除成功");
    }
}
